package penguin.service;

import org.springframework.stereotype.Service;
import penguin.data.RegisterData;

import java.util.*;

/**
 * Created on 15/7/10 下午3:04
 *
 * @author 王建华(penguin83@126.com)
 */
@Service("registerService")
public class RegisterService {


    /**
     * 注册 远程项目，同时也用于心跳
     * @param projectName
     * @param host
     * @param port
     * @param remoteProjectSet
     * @return
     */
    public Map<String,List<String>> getProjectAddressMap(String projectName,String host,Integer port, ArrayList<String> remoteProjectSet){

        String projectHostPort = host+":"+port;

        RegisterData.inst().registerProject(projectName,projectHostPort);


        Map<String,List<String>> projectAddressMap = new HashMap<String, List<String>>();

        for(String projectNameTemp:remoteProjectSet) {

            List<String> addressList = RegisterData.inst().getProjectAddressList(projectNameTemp);

            projectAddressMap.put(projectNameTemp,addressList);

        }

        return projectAddressMap;

    }

}
